<!-- 关联人员 -->
<template>
	<view class="">
		<u-sticky offset-top="0">
			<u-search class="search" :inputStyle="{marginLeft: '12rpx'}" shape="square" placeholder="请输入入职人员姓名"
				v-model="name" :show-action="false" @search="searchMsg" @clear="searchMsg" @blur="searchMsg"
				searchIconColor="#C6C6C6" placeholderColor="#C6C6C6" color="#7F7F7F">
			</u-search>
		</u-sticky>
		<view class="page"
			:style="!isData?'display:flex;width: 100vw;height:100vh;align-items:center;justify-content: center;':''">
			<template v-if="isData">
				<view class="list" v-for="(item,index) in dataList" :key="index" @click="onChecker(item, index)">
					<view class="">
						<view class="option">
							<view class="lf">姓名</view>
							<view class="rl">{{ item.name }}</view>
						</view>
						<view class="option">
							<view class="lf">性别</view>
							<view class="rl">{{ item.gender_dictText }}</view>
						</view>
						<view class="option">
							<view class="lf">应聘岗位</view>
							<view class="rl">{{ item.applyPosition_dictText }}</view>
						</view>
						<view class="option">
							<view class="lf">工作经验</view>
							<view class="rl">{{ item.workTime_dictText }}</view>
						</view>
						<view class="option">
							<view class="lf">面试日期</view>
							<view class="rl">{{ item.actualInterviewTime }}</view>
						</view>
						<view class="option">
							<view class="lf">面试结果</view>
							<view class="rl">{{ item.interviewResult_dictText }}</view>
						</view>
						<view class="option">
							<view class="lf">人才标签</view>
							<view class="rl">{{ item.talentLabel_dictText }}</view>
						</view>
					</view>
					<view class="icon" v-show="item.isChecker"><u-icon name="checkbox-mark" color="#2979ff"
							size="22"></u-icon></view>
				</view>
				<!-- 加载更多显示 -->
				<view class=""><u-loadmore :status="statusLoadmore" /></view>
			</template>
			<view v-else>
				<u-empty mode="data" icon="/static/empty/data.png">
				</u-empty>
			</view>
			<view style="height: 100rpx;"></view>
			<view class="btn">
				<u-button text="确定" type="primary" @click="onConfirm"></u-button>
			</view>
		</view>

		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import {
		queryEntryPersonList
	} from '@/api/index.js'
	export default {

		data() {
			return {
				sealCompany: '',
				showNotify: true, // 消息提示
				id: '', // 选中的id
				page: {
					pageNo: 1,
					pageSize: 10,
				},
				dataList: [], // 列表
				statusLoadmore: 'loadmore', // 通过status设置组件的状态，加载前值为loadmore，加载中为loading，没有数据为nomore
				oldIndex: 0, // 存储列表之前被选中的数据
				screenShow: false, // 筛选弹窗
				name: '', //筛选入职人员姓名
				applyId: '',
				objectField: '', // 点击确认需要修改的字段
			}
		},
		computed: {
			isData() {
				return !!this.dataList.length
			}
		},
		onLoad(options) {
			this.applyId = options.applyId
			this.getList() // 获取列表
		},
		methods: {
			searchMsg() {
				this.page.pageNo = 1
				this.getList(true)
			},
			// 获取列表
			getList(flag) {
				this.statusLoadmore = 'loading' // 加载中
				var params = {
					
						interviewResult: 1,
						...this.page,
						
				}
				if (this.name) {
					params.name = this.name
				}
				queryEntryPersonList(params).then(res => {
					if (res.success && res.result?.records?.length) {
						const {
							records
						} = res.result
						const dataList = records.map(i => {
							i.isChecker = this.applyId == i.id
							return i
						})
						if (flag) {
							this.dataList = dataList
						} else {
							this.dataList = [...this.dataList, ...dataList]
						}
						this.statusLoadmore = 'nomore'
					} else {
						this.dataList = []
						this.statusLoadmore = 'nomore'
					}
				})
			},
			// 点击选中取消选中
			onChecker(item, index) {
				this.dataList.map(i => i.isChecker = false)
				item.isChecker = !item.isChecker
			},
			onReachBottom() {
				this.page.pageNo++
				this.getList()
			},
			// 点击确定
			onConfirm() {
				const selectedData = this.dataList.find(i => i.isChecker)
				if (!selectedData) {
					this.$refs.uToast.show({
						type: 'error',
						icon: 'none',
						message: '请选择数据'
					})
					return
				}
				let pages = getCurrentPages()
				let prevPage = pages[pages.length - 2] //上一页页面实例
				prevPage.$vm.model.applyId = selectedData.id
				uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});
			}
		},
	}
</script>
<style lang="scss" scoped>
	.page {
		padding: 0 20rpx 20rpx 20rpx;

		.list {
			border-radius: 10rpx;
			box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.1);
			padding: 12rpx 20rpx 20rpx 20rpx;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;
		}
	}

	// 按钮
	.btn {
		position: fixed;
		bottom: 20rpx;
		width: 95%;
	}

	.search {
		width: 750rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #FFFFFF;
		padding: 10rpx 40rpx;
		box-sizing: border-box;
	}
</style>